<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>用户信息</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f5f5f5;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
    }
    .user-container {
      background-color: white;
      padding: 30px;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      width: 400px;
    }
    .user-container h2 {
      text-align: center;
      margin-bottom: 20px;
      color: #333;
    }
    .info-group {
      margin-bottom: 15px;
      padding: 10px;
      border: 1px solid #eee;
      border-radius: 5px;
    }
    .info-group label {
      font-weight: bold;
      color: #555;
      display: inline-block;
      width: 80px;
    }
    .btn {
      width: 100%;
      padding: 10px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      font-size: 16px;
      margin-top: 10px;
    }
    .btn:hover {
      background-color: #0056b3;
    }
    .message {
      text-align: center;
      margin-top: 15px;
      padding: 10px;
      border-radius: 5px;
    }
    .error {
      background-color: #f8d7da;
      color: #721c24;
      border: 1px solid #f5c6cb;
    }
    .success {
      background-color: #d4edda;
      color: #155724;
      border: 1px solid #c3e6cb;
    }
  </style>
</head>
<body>
<div class="user-container">
  <h2>用户信息</h2>
  <div id="userInfo">
    <!-- 用户信息将通过JavaScript动态加载 -->
  </div>
  <button id="logoutBtn" class="btn">退出登录</button>
  <div id="message"></div>
</div>

<script>
  // 从URL参数获取手机号
  const urlParams = new URLSearchParams(window.location.search);
  const phoneNumber = urlParams.get('phoneNumber');

  if (!phoneNumber) {
    document.getElementById('userInfo').innerHTML = '<p>未找到用户信息</p>';
  } else {
    // 获取用户信息
    fetch(`/auth/userInfo?phoneNumber=${encodeURIComponent(phoneNumber)}`)
            .then(response => response.json())
            .then(data => {
              if (data.success) {
                const user = data.data;
                document.getElementById('userInfo').innerHTML = `
                        <div class="info-group">
                            <label>用户ID:</label>
                            <span>${user.visitorId}</span>
                        </div>
                        <div class="info-group">
                            <label>姓名:</label>
                            <span>${user.visitorsName}</span>
                        </div>
                        <div class="info-group">
                            <label>手机号:</label>
                            <span>${user.phoneNumber}</span>
                        </div>
                        <div class="info-group">
                            <label>邮箱:</label>
                            <span>${user.email}</span>
                        </div>
                        <div class="info-group">
                            <label>创建时间:</label>
                            <span>${formatDate(user.createTime)}</span>
                        </div>
                        <div class="info-group">
                            <label>更新时间:</label>
                            <span>${formatDate(user.updateTime)}</span>
                        </div>
                    `;
              } else {
                document.getElementById('userInfo').innerHTML = `<p>${data.message}</p>`;
              }
            })
            .catch(error => {
              console.error('Error:', error);
              document.getElementById('userInfo').innerHTML = '<p>获取用户信息失败</p>';
            });
  }

  // 退出登录
  document.getElementById('logoutBtn').addEventListener('click', function() {
    // 清除可能的登录状态并跳转到登录页
    window.location.href = 'login.html';
  });

  // 格式化日期
  function formatDate(dateString) {
    if (!dateString) return '';
    const date = new Date(dateString);
    return date.toLocaleString('zh-CN');
  }
</script>
</body>
</html>